#include <stdio.h>
#include <stdlib.h>
#define N 10000
int arr[N+1]= {0};
int main_4()
{
    int n,v,cnt=0;
    scanf("%d",&n);
    for (int i=0; i<n ; i++ )
    {
        scanf("%d",&v);
        arr[v]=1;
        cnt+=arr[v+1]+arr[v-1];
    }
    printf("%d\n",cnt);
    return 0;
}
